/**   
 * Copyright © 2019 eSunny Info. Tech Ltd. All rights reserved.
 * 
 * @Description:TODO(功能)
 * @className CustomersServiceImpl.java
 * @Package: com.erp.service 
 * @author: yj   
 * @date: 2019年2月22日 下午4:01:15 
 */
package com.erp.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.erp.dao.CustomersDaoImpl;
import com.erp.po.Customers;
import com.erp.util.DBHelper;

/**
 * @className CustomersServiceImpl.java
 * @author yj
 * @Description:TODO(功能)
 * @Date 2019年2月22日
 */
public class CustomersServiceImpl implements CustomersService {

	private CustomersDaoImpl cd;
	
	public CustomersServiceImpl() {
		cd = new CustomersDaoImpl();
	}
	
	/* 
	 * 使用ajax 查询custs数据
	 */
	@Override
	public List<Customers> findAllCusts() {
		Connection conn = null;
		ArrayList<Customers> list = new ArrayList<Customers>();
		
		try {
			conn = DBHelper.getConnection();
			
			ResultSet set = cd.selectAllCusts(conn);
			while (set.next()) {
				int customerID = set.getInt("CUSTOMERID");
				String customerName = set.getString("CUSTOMER_NAME");
				
				list.add(new Customers(customerID, customerName));
			}
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			cd.close();
		}
		return null;
	}

}
